package com.anxinr.controller;

import com.anxinr.pojo.entity.Cookie;
import com.anxinr.pojo.entity.Goods;
import com.anxinr.result.Result;
import com.anxinr.service.ICookieService;
import com.anxinr.service.IGoodsService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author anxinr
 */
@Slf4j
@RestController
@RequestMapping("/cookie")
public class CookieController {
    @Autowired
    private ICookieService cookieService ;

    @PostMapping("/query")
    public Result<IPage<Cookie>> query(@RequestBody Cookie cookie){
        return new Result(cookieService.queryUsers(cookie)) ;
    }

    @PostMapping("/save")
    public Result save(@RequestBody Cookie cookie) throws Exception {
        try {
            return new Result(cookieService.save(cookie)) ;
        }catch (Exception e){
            e.printStackTrace();
            throw e ;
        }
    }

    @PostMapping("/update")
    public Result update(@RequestBody Cookie cookie) throws Exception {
        try {
            return new Result(cookieService.updateById(cookie)) ;
        }catch (Exception e){
            e.printStackTrace();
            throw e ;
        }
    }

    @GetMapping("/remove")
    public Result remove(@RequestParam("key") String key){
        try {
            LambdaUpdateWrapper<Cookie> wrapper = new LambdaUpdateWrapper<>();
            wrapper.eq(Cookie::getCokey,key);
            cookieService.remove(wrapper);
            return Result.success() ;
        }catch (Exception e){
            e.printStackTrace();
            throw e ;
        }
    }
    
}
